package cn.edu.neu.vmmigeval.cloud.policy.impl;


import cn.edu.neu.vmmigeval.cloud.entity.Host;
import cn.edu.neu.vmmigeval.cloud.entity.Vm;
import cn.edu.neu.vmmigeval.cloud.policy.MigratedHostPolicy;
import cn.edu.neu.vmmigeval.cloud.policy.VmSelectionPolicy;

import java.util.List;
import java.util.Random;

/**
 * The Random Selection (RS) Broker selection policy.
 * @author zzh
 *
 */
public class VmSelectionPolicyRandomSelection extends VmSelectionPolicy {

	public VmSelectionPolicyRandomSelection(
			MigratedHostPolicy migratedHostPolicy) {
		super(migratedHostPolicy);
	}
	
	public VmSelectionPolicyRandomSelection() {
	}

	@Override
	public Vm getVmToMigrate(Host host) {
		List<Vm> migratableVms = getMigratableVms(host);
		if (migratableVms.isEmpty()) {
			return null;
		}
		int index = (new Random()).nextInt(migratableVms.size());
		return migratableVms.get(index);
	}

}
